package cn.tx.service.impl;

import cn.tx.mapper.OrderSettingDao;
import cn.tx.pojo.OrderSetting;
import cn.tx.service.OrderSettingService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author Snake Eyes
 * @PROJECT_NAME: health_parent
 * @DESCRIPTION:
 * @USER: 11647
 * @DATE: 2021/9/2 16:19
 * @Email: 1164763541@qq.com
 */
@Service(interfaceClass = OrderSettingService.class)
@Transactional
public class OrderSettingServiceImpl implements OrderSettingService {
    @Autowired
    private OrderSettingDao orderDao;


    @Override
    public void save(List<OrderSetting> data) {
        if (data != null && data.size() > 0) {
            for (OrderSetting orderSetting : data) {
                //检查此数据（日期）是否存在
                OrderSetting count = orderDao.selectFindByDate(orderSetting.getOrderDate());
                if (count != null) {
                    //已经存在，执行更新操作
                    orderDao.update(orderSetting);
                } else {
                    //不存在，执行添加操作
                    orderDao.save(orderSetting);
                }
            }
        }
    }

    //通过日期控件设置预约数据
    @Override
    public List<Map> orderSet(OrderSetting day) {
        //获取到时间
        Date orderDate = day.getOrderDate();
        //格式化date数据
        String format = new SimpleDateFormat("yyyy-MM-dd").format(orderDate);
        //判断是否存在当前日期的数据
        OrderSetting orderSetting = orderDao.selectFindByDate(day.getOrderDate());
        if (orderSetting != null) {
            orderDao.update(day);
        } else {
            //添加数据
            orderDao.save(day);
        }
        return null;
    }


}
